﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.11f1
 *Date:           2019-04-13
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using System;
using System.IO;
namespace IFramework
{
	public class IO
	{
        public enum FileSizeLev
        {
            B=0,KB,MB,GB,TB
        }
        public static string GetFileSize(string filePath)
        {
            if (!File.Exists(filePath) && !Directory.Exists(filePath)) return string.Empty;
            FileInfo info = new FileInfo(filePath);
            long length = info.Length;
            int lev = 0;
            if (length==0) return info.Length + " " + ((FileSizeLev)0).ToString();
            while (length / 1024>0)
            {
                length /= 1024;
                lev++;
            }
            return Math.Round(info.Length / Math.Pow(1024, lev),2).ToString()  + " " + ((FileSizeLev)lev).ToString();
        }
        public static string GetFileSize(long length)
        {
            int lev = 0;
            long len = length;
            if (length == 0) return "0 " + ((FileSizeLev)0).ToString();
            while (len / 1024 > 0)
            {
                len /= 1024;
                lev++;
            }
            return Math.Round(length/ Math.Pow(1024, lev), 2).ToString() + " " + ((FileSizeLev)lev).ToString();
        }
    }
}
